package cn.wit.summit.chwan.adapters;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import cn.wit.summit.chwan.R;
import cn.wit.summit.chwan.utils.MyImageLoader;

/**
 * Created by hezl on 2015/1/5.
 */
public class GameDetailAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater layoutInflater;
    private List<String> strings = new ArrayList<String>();
    private boolean isVideo;
    private int isVertical;

    public GameDetailAdapter(Context context) {
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
    }

    public GameDetailAdapter(Context context, int pic_position, List<String> strings, boolean isVideo) {
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
        this.strings = strings;
        this.isVertical = pic_position;
        this.isVideo = isVideo;
    }

    public List<String> getItems() {
        return this.strings;
    }

    @Override
    public int getCount() {
        return strings.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View convertView, ViewGroup viewGroup) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.game_detail_item, null);

            holder = new ViewHolder();
            holder.imageViewVPic = (SimpleDraweeView) convertView
                    .findViewById(R.id.imageViewVPic);
            holder.imageViewHPic = (SimpleDraweeView) convertView
                    .findViewById(R.id.imageViewHPic);
//            holder.imageViewPlay = (ImageView) convertView
//                    .findViewById(R.id.imageViewPlay);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (isVertical == 1) {
            holder.imageViewVPic.setVisibility(View.VISIBLE);
            holder.imageViewHPic.setVisibility(View.GONE);
            MyImageLoader.load(  holder.imageViewVPic,strings.get(i));
        } else {
            holder.imageViewHPic.setVisibility(View.VISIBLE);
            holder.imageViewVPic.setVisibility(View.GONE);
            MyImageLoader.load(holder.imageViewHPic, strings.get(i));
        }
//
//        if (i == 0 && this.isVideo) {
//            holder.imageViewPlay.setVisibility(View.VISIBLE);
//        } else {
//            holder.imageViewPlay.setVisibility(View.GONE);
//        }
        return convertView;
    }


    private class ViewHolder {
        SimpleDraweeView imageViewVPic;
        SimpleDraweeView imageViewHPic;
//        ImageView imageViewPlay;
    }
}
